package com.jmlee.service.impl;


import com.jmlee.mapper.AItemParamMapper;
import com.jmlee.mapper.AItemsImgMapper;
import com.jmlee.mapper.AItemsMapper;
import com.jmlee.pojo.AItem;
import com.jmlee.pojo.AItemImg;
import com.jmlee.pojo.AItemParam;

import java.util.List;

import com.jmlee.service.AItemService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AItemServiceImpl implements AItemService {
    @Autowired
    private AItemsMapper aItemsMapper;
    @Autowired
    private AItemParamMapper aItemParamMapper;
    @Autowired
    private AItemsImgMapper aItemsImgMapper;

    public AItemServiceImpl() {
    }

    public List<AItem> getItemsList(RowBounds rowBounds, AItem aItem) {
        if (rowBounds != null) {
            return aItem != null ? this.aItemsMapper.selectItemList(rowBounds, aItem) : this.aItemsMapper.selectItemList(rowBounds);
        } else {
            return aItem != null ? this.aItemsMapper.selectItemList(aItem) : this.aItemsMapper.selectItemList();
        }
    }

    public Integer editItemInfo(AItem aItem) {
        return this.aItemsMapper.updateItem(aItem);
    }

    @Override
    public Integer editItemParam(AItemParam aItemParam) {
        return aItemParamMapper.updateItemParam(aItemParam);
    }

    public Integer addItemInfo(AItem aItem) {
        return this.aItemsMapper.insertItem(aItem);
    }

    public Integer addItemParam(Long itemId, AItemParam aItemParam) {
        aItemParam.setItemId(itemId);
        return this.aItemParamMapper.insertItemParam(aItemParam);
    }

    public Long selectItemIdByItemName(String itemName) {
        return this.aItemsMapper.selectItemIdByItemName(itemName);
    }

    @Override
    public AItemParam getAItemParam(Long itemId) {
        return aItemParamMapper.selectItemParam(itemId);
    }

    public Integer addItemImage(AItemImg aItemImg) {
        return this.aItemsImgMapper.insertImg(aItemImg);
    }

    public List<AItemImg> getAItemImg(Long itemId) {
        return this.aItemsImgMapper.selectImgList(itemId);
    }

    public AItemImg getAItemImg(String url) {
        return this.aItemsImgMapper.selectImg(url);
    }

    public Integer editImageInfo(AItemImg aItemImg) {
        return this.aItemsImgMapper.uploadImg(aItemImg);
    }

    @Override
    public Long getRecordCount(AItem aItem) {
        return aItemsMapper.selectItemsCount(aItem);
    }
}
